package com.suxin.okhttp.http.core.request;


import com.suxin.okhttp.http.core.GsonUtil;
import com.suxin.okhttp.http.core.MediaType;

import static java.util.Objects.requireNonNull;

/**
 * @Author: tang
 * @Description:
 * @Date 2024/11/27 14:52
 */
public class JsonRequestBody implements RequestBody {

    private final String body;

    private JsonRequestBody(String body) {
        this.body = body;
    }

    /**
     * 获取请求体
     *
     * @return 请求体
     */
    public String getBody() {
        return body;
    }

    @Override
    public String getContentType() {
        return MediaType.APPLICATION_JSON.getValue();
    }

    @Override
    public String toString() {
        return GsonUtil.getGson().toJson(this);
    }

    public static class Builder {

        private String body;

        public Builder body(String body) {
            this.body = body;
            return this;
        }

        public JsonRequestBody build() {
            return new JsonRequestBody(requireNonNull(body));
        }
    }
}
